﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using WeiTalk.Controls;
using WeiTalk.SinaEntities.Status;
using System.Windows.Media.Imaging;
using Microsoft.Phone.Shell;
using System.Text.RegularExpressions;
using RestSharp;
using WeiTalk.Interfaces.Sina;
using WeiTalk.SinaEntities.Search;

namespace WeiTalk
{
    public partial class MessagePage : PhoneApplicationPage
    {
        string atMeMax_id = "0";
        DateTime Now = DateTime.Now;
        DateTime perTime = DateTime.Now;

        PullAndDownControl reflashAtMeControl = new PullAndDownControl();
        private double actuableOffset, validStartOffset;
        private bool mplStarted;
        private bool isUpdating = false;
        private string atMeSince_id = "0";
        string locker = "1";
        bool isAtMeNoItem = false;
        const string isAtMeNoItemKey = "MessagePageIdIsAtMeNoItemKey";
        const string atMeSince_idKey = "MessagePageIdAtMeSince_idKey";
        const string atMeMax_idKey = "MessagePageIdAtMeMax_idKey";
        ImageViewer imageViewer = new ImageViewer();
        double width = System.Windows.Application.Current.Host.Content.ActualWidth;
        const string piAtMeName = "piAtMe";

        #region 新浪不开放私信
        //bool isPeopleLoaded = false;
        //const string isPeopleLoadedKey = "MessagePageIsPeopleLoadedKey";
        //PullAndDownControl reflashPeopleControl = new PullAndDownControl();
        //StackPanel spPeopleGetMore = new StackPanel();
        //int cursor = 0;
        //const string cursorKey = "MessagePageIdCursorKey";
        //Button btnPeopleGetMore = null;

        //double gap = 5d;
        //const string piPersonalMessageName = "piPersonalMessage";
        //const string piRecentlyPersonalMessageName = "piRecentlyPersonalMessage";

        //string messageSince_id = "0";
        //const string messageSince_idKey = "MessagePageMessageSince_idKey";
        //string messageMax_id = "0";
        //const string messageMax_idKey = "MessagePageMessageMax_idKey";
        //StackPanel spMessageGetMore = new StackPanel();
        //Button btnMessageGetMore = null;
        //bool isMessageLoaded = false;
        //const string isMessageLoadedKey = "MessagePageisMessageLoadedKey";
        //PullAndDownControl reflashMessagesControl = new PullAndDownControl(); 
        #endregion

        public MessagePage()
        {
            InitializeComponent();
            spContent.Width = width - 10;
        }

        #region @Me
        private void AddWeiBoItems(List<WeiTalk.SinaEntities.Status.Content> data, bool isRefresh)
        {
            isAtMeNoItem = (data.Count == 1 && atMeMax_id != "0");
            if (data == null || data.Count == 0 || isAtMeNoItem)
            {
                lock (locker)
                {
                    isUpdating = false;
                    isAtMeNoItem = true;
                }
                WeiBoUtility.ShowToast("休息一下吧，没有新的更新...");
                Dispatcher.BeginInvoke(() =>
                {
                    ResetPullControl();
                });
                if (spContent.Children.Contains(reflashAtMeControl))
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        spContent.Children.Remove(reflashAtMeControl);
                    });
                }
                return;
            }

            //先删除加载更多按键，最后再加上
            Dispatcher.BeginInvoke(() =>
            {
                spContent.Children.Remove(reflashAtMeControl);
            });

            int index = 0;
            if (!isRefresh)
            {
                 Dispatcher.BeginInvoke(() =>
                {
                    if (!(spContent.Children[spContent.Children.Count - 1] is PullAndDownControl))
                    {
                        spContent.Children.RemoveAt(spContent.Children.Count - 1);
                    }
                });
            }
            int refreshIndex = 1;
            foreach (Content item in data)
            {
                if (atMeSince_id == "0" || (index == 0 && isRefresh))
                {
                    atMeSince_id = item.ID;
                }
                index++;

                atMeMax_id = item.ID;
                
                WeiBoControl control = new WeiBoControl();
                control.Name = String.Format("{0}_{1}", atMeSince_id, Guid.NewGuid().ToString());

                control.Click += new ClickEventHandler(WeiBoClick);
                control.ThumbnailPicClick += new ImageClickEventHandler(ThumbnailPicClick);
                control.RetweetedThumbnailPicClick += new ImageClickEventHandler(ThumbnailPicClick);
                control.Text = item.Text;
                control.CreatedAt = item.CreatedAt;

                if (item.User != null)
                {
                    control.UserName = item.User.Name;
                    control.OriginalPic = item.OriginalPic;
                    try
                    {
                        WeiBoUtility.RetrieveImage(item.User.ProfileImageUrl, (s) =>
                        {
                            BitmapImage bi = new BitmapImage();
                            bi.SetSource(s);
                            bi.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                            control.ProfileImageUrl = bi;

                        }, Dispatcher.BeginInvoke);
                    }
                    catch { }
                    control.Source = item.Source;
                    control.CommentCount = item.CommentsCount.ToString();
                    control.RepostsCount = item.RepostsCount.ToString();
                    control.Id = item.ID;
                    control.UserId = item.User.ID;
                    if (item.RetweetedStatus != null)
                    {
                        control.RetweetedId = item.RetweetedStatus.ID;
                        control.RetweetedContent = item.RetweetedStatus.Text;
                        control.RetweetedOriginalPic = item.RetweetedStatus.OriginalPic;
                        if (item.RetweetedStatus.User != null)
                        {
                            control.RetweetedUserId = item.RetweetedStatus.User.ID;
                            control.RetweetedUserName = item.RetweetedStatus.User.Name;
                            control.RetweetedCreateAt = item.RetweetedStatus.CreatedAt;
                        }
                        if (!String.IsNullOrEmpty(item.RetweetedStatus.ThumbnailPic))
                        {
                            try
                            {
                                control.RetweetedThumbnailPic = item.RetweetedStatus.ThumbnailPic;
                            }
                            catch { }
                        }

                        control.RetweetedSource = item.RetweetedStatus.Source;
                        control.RetweetedRepostsCount = item.RetweetedStatus.RepostsCount.ToString();
                        control.RetweetedCommentCount = item.RetweetedStatus.CommentsCount.ToString();
                    } 
                }

                if (!String.IsNullOrEmpty(item.ThumbnailPic))
                {
                    try
                    {
                        control.ThumbnailPic = item.ThumbnailPic;
                    }
                    catch { }
                }

                Dispatcher.BeginInvoke(() =>
                  {
                      if (!isRefresh)
                      {
                          spContent.Children.Add(control);
                      }
                      else
                      {
                          spContent.Children.Insert(refreshIndex, control);
                          refreshIndex++;
                      }
                  });
            }
            Dispatcher.BeginInvoke(() =>
            {
                if (data.Count > 0)
                {
                    spContent.Children.Add(reflashAtMeControl);
                }
                //如果有更新，需要重置刷新控件
                ResetPullControl();
                WeiBoUtility.ShowToast(String.Format("你有{0}条更新.", data.Count));
            });
            lock (locker)
            {
                isUpdating = false;
            }
        }

        private void WeiBoClick(object sender, EventArgs e)
        {
            WeiBoControl control = (WeiBoControl)sender;
            control.sbSelected.Begin();
            control.sbSelected.Completed += (s, ev) =>
            {
                WeiBoShow.ParentControl = control;
                NavigationService.Navigate(new Uri("/WeiBoShow.xaml", UriKind.Relative));

            };
        }

        private void ThumbnailPicClick(object sender, ImageEventArgs e)
        {
            ApplicationBarIconButton mibtnLoading = FindLoadingButton();
            if (mibtnLoading == null)
            {
                return;
            }
            WeiBoUtility.ShowToast("正在下载图片...");
            WeiBoControl control = (WeiBoControl)sender;
            mibtnLoading.IsEnabled = false;
            WeiBoUtility.RetrieveImageByOne(e.ImageUrl, s =>
            {
                mibtnLoading.IsEnabled = true;
                mibtnLoading.Text = Constant.loadedMsg;
                imageViewer.Source = s;
                imageViewer.Control = control;
                imageViewer.IsReady = true;
                imageViewer.IsGif = Regex.IsMatch(e.ImageUrl, ".gif$", RegexOptions.IgnoreCase);
                WeiBoUtility.ShowToast("下载完成,点击查看...");
                this.ApplicationBar.Mode = ApplicationBarMode.Default;
            }, Dispatcher.BeginInvoke);
        }

        private ApplicationBarIconButton FindLoadingButton()
        {
            foreach (object button in this.ApplicationBar.Buttons)
            {
                if (button is ApplicationBarIconButton &&
                    (((ApplicationBarIconButton)button).Text == Constant.loadingMsg ||
                    ((ApplicationBarIconButton)button).Text == Constant.loadedMsg))
                {
                    return (ApplicationBarIconButton)button;
                }
            }
            return null;
        }

        private void ResetPullControl()
        {
            pullAndDownControl.Margin = new Thickness(0, -50, 0, 20);
            pullAndDownControl.Busy = false;
            pullAndDownControl.Ready = false;
        }

        private void UpdateAtMe_TimeLine(bool update, bool isNextPage = false)
        {
            if (isUpdating)
            {
                return;
            }
            var client = new RestClient();
            StatusAPIs status = new StatusAPIs(client);
            string sinceId = update ? atMeSince_id : "0";
            string maxId = update ? "0" : atMeMax_id;
            status.GetMentions((result) =>
            {
                if (result.Data == null)
                {
                    WeiBoUtility.ShowToast("更新异常，请重试。");
                    return;
                }
                List<WeiTalk.SinaEntities.Status.Content> data = ((WeiTalk.SinaEntities.Status.Entity)result.Data).Statuses;

                AddWeiBoItems(data, update);

            }, sinceId, maxId, 1, 0, 0, 0, 0);
        }

        private void mibtnRefresh_Click(object sender, EventArgs e)
        {
            if (pMessage.SelectedItem != null &&
                       ((PivotItem)pMessage.SelectedItem).Name == piAtMeName)
            {
                pullAndDownControl.Busy = true;
                pullAndDownControl.Text = "正在更新...";
                pullAndDownControl.Margin = new Thickness(0, 0, 0, 20);
                svAtMeTimeLine.ScrollToVerticalOffset(0d);
                UpdateAtMe_TimeLine(true);
            }
            #region 新浪不支持私信接口
            //else if(pMessage.SelectedItem != null &&
            //           ((PivotItem)pMessage.SelectedItem).Name == piPersonalMessageName)
            //{
            //    cursor = 0;
            //    isPeopleLoaded = false;
            //    spPeople.Children.Clear();
            //    Pivot_SelectionChanged(pMessage, null);
            //} 
            #endregion

        }

        private void ResetLoadingControl()
        {
            imageViewer.IsReady = false;
            ApplicationBarIconButton mibtnLoading = FindLoadingButton();
            if (mibtnLoading == null)
            {
                return;
            }
            mibtnLoading.Text = Constant.loadingMsg;
            mibtnLoading.IsEnabled = false;
        }

        private void svAtMeTimeLine_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            int count = spContent.Children.Count;

            //head
            if (actuableOffset > Constant.UpdateHeight && svAtMeTimeLine.VerticalOffset < 1)
            {
                pullAndDownControl.Busy = true;
                pullAndDownControl.Text = "正在更新...";
                pullAndDownControl.Margin = new Thickness(0, 0, 0, 20);
                UpdateAtMe_TimeLine(true);
            }
        }

        private void svatMeTimeLine_MouseMove(object sender, MouseEventArgs e)
        {
            //head capture startRelative
            if (svAtMeTimeLine.VerticalOffset < 1)
            {
                if (mplStarted)
                {
                    mplStarted = false;
                    validStartOffset = e.GetPosition(null).Y;
                }
                actuableOffset = e.GetPosition(null).Y - validStartOffset;
            }
            //tail
            if (svAtMeTimeLine.VerticalOffset == svAtMeTimeLine.ScrollableHeight)
            {
                if (mplStarted)
                {
                    mplStarted = false;
                    validStartOffset = e.GetPosition(null).Y;
                }
                actuableOffset = e.GetPosition(null).Y - validStartOffset;
            }
            if (svAtMeTimeLine.VerticalOffset < 1)
            {
                pullAndDownControl.Busy = false;
                if (actuableOffset > Constant.UpdateHeight)
                {

                    pullAndDownControl.Ready = true;
                    pullAndDownControl.Text = "松手可以更新...";
                }
                else
                {
                    if (pullAndDownControl.Ready)
                    {
                        pullAndDownControl.Ready = false;
                    }
                    pullAndDownControl.Text = "下拉可以更新...";
                }

            }
        }

        private void svAtMeTimeLine_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            mplStarted = true;
        }

        private void ImageViewer_Click(object sender, EventArgs e)
        {
            if (imageViewer.IsReady)
            {
                ImageViewerPage.Source = imageViewer.Source;
                ImageViewerPage.ParentControl = imageViewer.Control;
                ImageViewerPage.IsGif = imageViewer.IsGif;
                NavigationService.Navigate(new Uri("/ImageViewerPage.xaml", UriKind.Relative));
            }
            ResetLoadingControl();
        } 
        #endregion

        private bool IsPageFirstLoaded()
        {
            return !State.ContainsKey(atMeSince_idKey) || State[atMeSince_idKey] == null;
        }

        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            #region 新浪不开放私信接口
            //Pivot parentControl = (Pivot)sender;
            //if (parentControl.SelectedItem != null &&
            //           !isPeopleLoaded &&
            //           ((PivotItem)parentControl.SelectedItem).Name == piPersonalMessageName)
            //{
            //    if (String.IsNullOrEmpty(WeiTalk.OAuth.Utility.AccessToken.UID))
            //    {
            //        throw new ArgumentNullException("ID 为空.");
            //    }

            //    btnPeopleGetMore = new Button();
            //    spPeopleGetMore.Children.Add(btnPeopleGetMore);
            //    btnPeopleGetMore.FontSize = 18.667d;
            //    btnPeopleGetMore.FontWeight = FontWeights.Bold;
            //    btnPeopleGetMore.BorderThickness = new Thickness(0d);
            //    btnPeopleGetMore.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            //    btnPeopleGetMore.Margin = new Thickness(0, 0, 0, 30);
            //    btnPeopleGetMore.Click += new RoutedEventHandler(GetMorePeople_Click);

            //    GetPeople();
            //    isPeopleLoaded = true;
            //}
            //else if (parentControl.SelectedItem != null &&
            //           !isMessageLoaded &&
            //           ((PivotItem)parentControl.SelectedItem).Name == piRecentlyPersonalMessageName)
            //{
            //    btnMessageGetMore = new Button();
            //    spMessageGetMore.Children.Add(btnMessageGetMore);
            //    btnMessageGetMore.FontSize = 18.667d;
            //    btnMessageGetMore.FontWeight = FontWeights.Bold;
            //    btnMessageGetMore.BorderThickness = new Thickness(0d);
            //    btnMessageGetMore.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            //    btnMessageGetMore.Margin = new Thickness(0, 0, 0, 30);
            //    btnMessageGetMore.Click += new RoutedEventHandler(GetMorePeople_Click);

            //    GetRecentlyMessages();
            //    isMessageLoaded = true;
            //} 
            #endregion
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            State[atMeSince_idKey] = atMeSince_id;
            State[atMeMax_idKey] = atMeMax_id;
            #region 新浪不开放私信接口
            //State[cursorKey] = cursor;
            //State[isPeopleLoadedKey] = isPeopleLoaded;
            //State[messageMax_idKey] = messageMax_id;
            //State[messageSince_idKey] = messageSince_id;
            //State[isMessageLoadedKey] = isMessageLoaded; 
            #endregion
            State[isAtMeNoItemKey] = isAtMeNoItem;
            base.OnNavigatedFrom(e);
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsPageFirstLoaded())
            {
                reflashAtMeControl.Busy = true;
                reflashAtMeControl.Text = "更新数据...";
                spContent.Children.Add(reflashAtMeControl);
                UpdateAtMe_TimeLine(false);

                ScrollViewerMonitor svm = new ScrollViewerMonitor(svAtMeTimeLine);
                svm.AtEnd += new EventHandler((s, ev) =>
                {
                    if (!isAtMeNoItem)
                    {
                        UpdateAtMe_TimeLine(false);
                    }
                });
            }
            else
            {
                atMeSince_id = State.ContainsKey(atMeSince_idKey) ? State[atMeSince_idKey] as string : "0";
                atMeMax_id = State.ContainsKey(atMeMax_idKey) ? State[atMeMax_idKey] as string : "0";
                #region 新浪不支持私信接口
                // cursor = State.ContainsKey(cursorKey) ? (int)State[cursorKey] : 0;
                //isPeopleLoaded = State.ContainsKey(isPeopleLoadedKey) ? (bool)State[isPeopleLoadedKey] : false;
                //messageSince_id = State.ContainsKey(messageSince_idKey) ? State[messageSince_idKey] as string : "0";
                //messageMax_id = State.ContainsKey(messageMax_idKey) ? State[messageMax_idKey] as string : "0";
                // isMessageLoaded = State.ContainsKey(isMessageLoadedKey) ? (bool)State[isMessageLoadedKey] : false; 
                #endregion
                isAtMeNoItem =  State.ContainsKey(isAtMeNoItemKey) ? (bool)State[isAtMeNoItemKey] : false;
            }
            ResetLoadingControl();
            this.ApplicationBar.Mode = ApplicationBarMode.Minimized;
        }

        #region 私信
        //private void btnSearch_Click(object sender, RoutedEventArgs e)
        //{
        //    if (!String.IsNullOrEmpty(tbSearch.Text.Trim()))
        //    {
        //        GetPeopleByName(tbSearch.Text);
        //    }
        //    else
        //    {
        //        spPeople.Children.Clear();
        //        EnablePeopleRefreshControl();
        //        cursor = 0;
        //        GetPeople();
        //    }
        //}

        //private void GetMorePeople_Click(object sender, RoutedEventArgs e)
        //{
        //    GetPeople();
        //}

        //private void GetPeople()
        //{
        //    var client = new RestClient();
        //    FriendshipsAPI friends = new FriendshipsAPI(client);
        //    EnablePeopleRefreshControl();
        //    friends.GetFriends(
        //        (result) =>
        //        {
        //            try
        //            {
        //                List<WeiTalk.SinaEntities.User.Entity> people = result.Data.Users;
        //                AddPeopleControl(people);
        //                cursor = result.Data.NextCursor;
        //            }
        //            catch
        //            {
        //                WeiBoUtility.ShowToast("获取数据异常,请重试...");
        //            }

        //        },
        //    WeiTalk.OAuth.Utility.AccessToken.UID, null, cursor);
        //}

        //private void GetPeopleByName(string screnName)
        //{
        //    var client = new RestClient();
        //    SearchAPI search = new SearchAPI(client);
        //    spPeople.Children.Clear();
        //    EnablePeopleRefreshControl();
        //    search.GetAtUser((users) =>
        //    {
        //        WeiTalk.SinaEntities.Search.AtUsers theUsers = users.Data;
        //        AddPeopleControl(theUsers);
        //    }, screnName);
        //}

        //private void ResetPeopleRefreshControl()
        //{
        //    if (spPeople.Children.Contains(reflashPeopleControl))
        //    {
        //        spPeople.Children.Remove(reflashPeopleControl);
        //    }
        //    if (spPeople.Children.Contains(spMessageGetMore))
        //    {
        //        spPeople.Children.Remove(spMessageGetMore);
        //    }
        //}

        //private void NoData()
        //{
        //    TextBlock tb = new TextBlock { Text = "没有相关数据..." };
        //    tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
        //    tb.Margin = new Thickness(0, 50, 0, 0);
        //    tb.FontSize = 18d;
        //    tb.FontStyle = System.Windows.FontStyles.Italic;
        //    spPeople.Children.Add(tb);
        //}

        //private void AddPeopleControl(WeiTalk.SinaEntities.Search.AtUsers users)
        //{
        //    if (users != null)
        //    {
        //        if (users.WeiTalk.Count == 0)
        //        {
        //            //WeiBoUtility.ShowToast("没有相关用户信息...");
        //            ResetPeopleRefreshControl();
        //            NoData();
        //            return;
        //        }
        //        spPeople.Children.Clear();

        //        var client = new RestClient();
        //        UserAPI userApi = new UserAPI(client);
        //        List<WeiTalk.SinaEntities.User.Entity> people = new List<WeiTalk.SinaEntities.User.Entity>();
        //        int finishedCounter = 0;
        //        foreach (AtUser user in users.WeiTalk)
        //        {
        //            userApi.GetShow(theUser =>
        //            {
        //                lock (people)
        //                {
        //                    people.Add(theUser.Data);
        //                    finishedCounter++;
        //                    if (finishedCounter == users.WeiTalk.Count)
        //                    {
        //                        AddPeopleControl(people);
        //                        cursor = 0;
        //                    }
        //                }
        //            }, user.UID);
        //        }
        //    }
        //}

        //private void AddPeopleControl(List<WeiTalk.SinaEntities.User.Entity> people)
        //{
        //    if (isUpdating)
        //    {
        //        return;
        //    }
        //    int index = 0;
        //    StackPanel sp = null;
        //    isUpdating = true;
        //    if (people.Count > 0)
        //    {
        //        btnPeopleGetMore.Content = "正在获取数据...";
        //        EnablePeopleRefreshControl();
        //    }
        //    else
        //    {
        //        btnPeopleGetMore.Content = "点击获取更多...";
        //        ResetPeopleRefreshControl();
        //        isUpdating = false;
        //        return;
        //    }
        //    Dispatcher.BeginInvoke(() =>
        //    {
        //        lock (locker)
        //        {
        //            foreach (var p in people)
        //            {
        //                if (index % 2 == 0)
        //                {
        //                    sp = new StackPanel();
        //                    sp.Orientation = System.Windows.Controls.Orientation.Horizontal;
        //                }
        //                PeopleControl control = new PeopleControl();
        //                control.Name = Guid.NewGuid().ToString();
        //                control.Id = p.ID;
        //                control.Width = width / 2d - gap;
        //                control.Name = p.Name;
        //                control.ScreenName = p.ScreenName;
        //                control.CreateAt = p.CreatedAt;
        //                control.FollowMe = p.FollowMe;
        //                WeiBoUtility.RetrieveImage(p.ProfileImageUrl,
        //                    (s) =>
        //                    {
        //                        BitmapImage bi = new BitmapImage();
        //                        bi.SetSource(s);
        //                        bi.CreateOptions = BitmapCreateOptions.BackgroundCreation;
        //                        control.headImg.Source = bi;

        //                    }, Dispatcher.BeginInvoke);
        //                if (!String.IsNullOrEmpty(p.Description))
        //                {
        //                    control.Descriotion = p.Description;
        //                }
        //                else
        //                {
        //                    control.Descriotion = "";
        //                }

        //                control.OnLineStatus = p.OnlineStatus == 1;
        //                sp.Children.Add(control);
        //                if (index % 2 == 0)
        //                {
        //                    spPeople.Children.Add(sp);
        //                }
        //                index++;

        //            }
        //            //如果只有一个用户，则需要增加一个隐藏控件，用于确保panel中的控件为双数。
        //            if (sp.Children.Count == 1)
        //            {
        //                sp.Children.Add(new StackPanel() { Width = width / 2d - gap });
        //            }
        //        }
        //        ResetPeopleRefreshControl();
        //        //还有下一页数据
        //        if (cursor > 0)
        //        {
        //            btnPeopleGetMore.Content = "点击获取更多...";
        //            spPeople.Children.Add(spMessageGetMore);
        //        }
        //        isUpdating = false;
        //    });
        //}

        //private void EnablePeopleRefreshControl()
        //{
        //    if (!spPeople.Children.Contains(reflashPeopleControl))
        //    {
        //        reflashPeopleControl.Busy = true;
        //        reflashPeopleControl.EnableImage = false;
        //        reflashPeopleControl.Text = "";
        //        spPeople.Children.Add(reflashPeopleControl);
        //    }
        //}

        #endregion

        #region 会话

        //private void EnableMessageRefreshControl()
        //{
        //    if (!spRecentlyPeopleMessages.Children.Contains(reflashMessagesControl))
        //    {
        //        reflashMessagesControl.Busy = true;
        //        reflashMessagesControl.EnableImage = false;
        //        reflashMessagesControl.Text = "";
        //        spRecentlyPeopleMessages.Children.Add(reflashMessagesControl);
        //    }
        //}
        //private void GetRecentlyMessages()
        //{
        //    var client = new RestClient();
        //    MessagesAPI messages = new MessagesAPI(client);
        //    EnableMessageRefreshControl();
        //    messages.GetDirectMessages(
        //        (result) =>
        //        {
        //            try
        //            {
        //                List<WeiTalk.SinaEntities.Messages.Entity> theMessages = result.Data.WeiTalk;
        //               // AddPeopleControl(theMessages);
        //            }
        //            catch
        //            {
        //                WeiBoUtility.ShowToast("获取数据异常,请重试...");
        //            }

        //        },
        //    "0");
        //}
        #endregion
    }
}